package com.litongjava.ai.server.padddle.ocr.controller;

import com.litongjava.ai.server.padddle.ocr.model.ChatMessage;
import com.litongjava.ai.server.padddle.ocr.model.ChatRequest;
import com.litongjava.ai.server.padddle.ocr.service.ChatService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.mvc.method.annotation.StreamingResponseBody;

import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;

@RestController
@RequestMapping("/api")
@CrossOrigin(origins = "*")
public class ChatController {

    @Autowired
    private ChatService chatService;

    /**
//     * 流式聊天接口
//     */
//    @PostMapping(value = "/chat", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
//    public StreamingResponseBody streamChat(@RequestBody ChatRequest request, HttpServletResponse response) {
//        response.setContentType(MediaType.TEXT_PLAIN_VALUE);
//        response.setCharacterEncoding("UTF-8");
//        return chatService.streamChat(request);
//    }
    /**
     * 流式聊天接口
     */
    @PostMapping(value = "/chat", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
    public StreamingResponseBody streamChat(@RequestBody ChatRequest request, HttpServletResponse response) {
        response.setContentType(MediaType.TEXT_PLAIN_VALUE);
        response.setCharacterEncoding("UTF-8");
        return chatService.streamChat(request);
    }
} 